from common.base import Base,By,sleep,open_browser

class BuyerLoginPage(Base):

    # 封装表现层，制作每个需要操作的元素的定位器
    username_locator = (By.NAME, 'login_info') # 用户名输入框
    password_locator = (By.NAME, 'password') # 密码输入框
    remember_locator = (By.NAME, 'remember') # 记住用户名单选框
    submit_locator = (By.CLASS_NAME, 'submit_login') # 提交按钮

    login_status_loc = (By.CLASS_NAME, 'f14')  # 登录成功，提示词元素


    # 封装操作层
    def input_username(self,username):
        self.send_keys(BuyerLoginPage.username_locator,username)

    def input_password(self,password):
        self.send_keys(BuyerLoginPage.password_locator,password)

    def remember_username(self):
        self.click(BuyerLoginPage.remember_locator)

    def click_login(self):
        self.click(BuyerLoginPage.submit_locator)

    def is_sucess_login(self,txt):
        text = self.get_element_text(BuyerLoginPage.login_status_loc)
        if text == txt:
            return True
        else:
            return False


if __name__ == '__main__':
    login = BuyerLoginPage(open_browser())
    login.get_url('http://172.16.0.205/shop/index.php?controller=simple&action=login')
    login.input_username('ceshi2001')
    login.input_password('ceshi2001')
    login.remember_username()
    login.click_login()
    sleep(3)
    login.driver.quit()



